<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>UserFiles</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiAdmin.std/src/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiAdmin.std/src/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/static/layuiAdmin.std/src/layuiadmin/style/template.css" media="all">
</head>
<body>



<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">文件名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="file_name" name="file_name" placeholder="文件名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" lay-submit lay-filter="btn-search" id="btnSearch">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        搜索一下
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layui-btn-danger" onclick="del_batch()">批量删除</button>
            </div>

            <div class="layui-fluid layadmin-maillist-fluid">
                <div class="layui-row layui-col-space15" id="dataList">

                </div>
            </div>

            <div id="page_bar"></div>

        </div>
    </div>


</div>
<script src="/static/layuiAdmin.std/src/layuiadmin/layui/layui.js"></script>
<script>
    var $;
    var form;
    var table;
    var page = 1;
    var count = 0;
    var laypage;

    function add() {
        layer.open({
            type: 2
            ,title: '创建UserFiles'
            ,content: 'edit?id=0'
            ,maxmin: true
            ,area: ['90%', '90%']
        });
    }

    function edit(id) {
        layer.open({
            type: 2
            ,title: '编辑UserFiles'
            ,content: 'edit?id=' + id
            ,maxmin: true
            ,area: ['90%', '90%']
        });
    }

    function del_batch() {
        var checkStatus = table.checkStatus('TableList')
        var checkData = checkStatus.data;
        if(checkData.length === 0){
            return layer.msg('请选择数据');
        }
        var ids = [];
        for (var i = 0; i < checkData.length; i++) {
            ids.push(checkData[i].id);
        }
        del(ids.join(','))
    }

    function del(ids) {
        layer.confirm('确定删除吗？', function(index) {
            $.ajax({
                url: 'del',
                type: 'POST',
                data: {
                    ids: ids
                },
                dataType: 'json',
                success: function (data) {
                    if (data.code == '0') {
                        layer.msg('删除成功', { icon: 1, time: 2000 }, function () {
                            layer.closeAll()
                            $('#btnSearch').click();
                        });
                    } else {
                        layer.msg(data.msg, { icon: 5, time: 2000 });
                    }
                }
            });
        });
    }

    function load_data() {
        $.ajax({
            url: 'list_html',
            type: 'GET',
            data: {
                file_name: $('#file_name').val(),
                page: page
            },
            dataType: 'json',
            success: function (data) {
                if (data.code == '0') {
                    $('#dataList').html(data.html)
                    count = data.count

                    render_page_bar()
                } else {
                    layer.msg(data.msg, { icon: 5, time: 2000 });
                }
            }
        });
    }

    function render_page_bar() {
        //分页
        laypage.render({
            elem: 'page_bar'
            ,count: count
            ,curr: page
            ,layout: ['count', 'prev', 'page', 'next',
                //'limit',
                'skip']
            ,jump: function(obj, first){
                console.log(obj)

                page = obj.curr
                if (!first) {
                    load_data()
                }
            }
        });
    }

    layui.config({
        base: '/static/layuiAdmin.std/src/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'table', 'laypage'], function(){
        $ = layui.$
        form = layui.form
        table = layui.table;
        laypage = layui.laypage;



        form.on('submit(btn-search)', function(data){
            page = 1;
            load_data()
        });

        load_data();


    });
</script>
</body>
</html>
